import router from "@/router";
import {HashMap} from "csap-typescript-vue2/lib";

export const ToPath = {
    /**
     * 名称跳转
     * @param name 页面的名称
     * @param params 参数
     */
    toName(name, param) {
        if (param != null) {
            sessionStorage.setItem("params", JSON.stringify(param));
        }
        HashMap.putAndFlush("back", {
            name: this.$route.name,
            fullPath: this.$route.fullPath,
            params: this.$route.params,
            path: this.$route.path,
            query: this.$route.query
        });
        HashMap.putAndFlush("paramsRuter", param);
        router.push({name: name, params: param});

    },
    /**
     * 路径跳转
     * @param path 路径
     * @param params 参数
     */
    toPath(path, params) {
        if (params != null) {
            sessionStorage.setItem("params", JSON.stringify(params));
        }
        router.push({path: path, query: params});
    },
    /**
     * 回退上一级页面
     * @param params
     */
    back(params) {
        let back = HashMap.get("back");
        if (back == null) {
            return;
        }
        // @ts-ignore
        router.push({name: back.name});
    }
}
